#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<stack>
using namespace std;

class MinStack {
public:
    /** initialize your data structure here. */
    MinStack() {

    }
    
    void push(int x) {
        S.push(x);
        if(!D.empty()&&D.back()>=x){
            D.push_back(x);
        }
        if(D.empty()){
            D.push_back(x);
        }
        
    }
    
    void pop() {
        if(S.empty()){
            return;
        }
        if(S.top()==D.back()){
            D.pop_back();
        }
        S.pop();
    }
    
    int top() {
        if(S.empty()){
            return -1;
        }
        return S.top();
    }
    
    int min() {
        if(S.empty()){
            return -1;
        }
        return D.back();
    }
public:
    stack<int> S;
    deque<int> D;
};

int main(){
    MinStack MS;
    MS.push(0);
    MS.push(1);
    MS.push(0);
    cout<<MS.min()<<endl;
    MS.pop();
    // cout<<MS.top()<<endl;
    cout<<MS.min()<<endl;
}